public class MyQueue {
    static class ListNode{
        private int val;
        private ListNode prev;
        private ListNode next;

        public ListNode(int val){
            this.val = val;
        }
    }

    private ListNode front;
    private ListNode rear;
    private int usedSize;

    public void offer(int x){
        ListNode node = new ListNode(x);
        if(this.front == null){
            this.front = node;
            this.rear = node;
        }else{
            this.rear.next = node;
            node.prev = this.rear;
            this.rear = node;
        }
        this.usedSize++;
    }

    public ListNode poll(){
        if(this.front == null){
            return null;
        }
        ListNode ret = this.front;
        this.usedSize--;
        if(this.front == this.rear){
            this.front = null;
            this.rear = null;
            return ret;
        }
        this.front = this.front.next;
        this.front.prev = null;
        return ret;
    }

    public ListNode peek(){
        if(this.front == null){
            return null;
        }
        return this.front;
    }

    public int size(){
        return this.usedSize;
    }

    public boolean isEmpty(){
        return this.usedSize == 0;
    }
}
